package h0903;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 比较版本号
 * @date 2024/9/3 11:43
 */
public class CompareVersion {
    public static int compareVersion(String version1, String version2) {
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");

        int n = Math.max(v1.length, v2.length);
        for (int i = 0; i < n; i++) {
            //parseInt可以忽略前导0
            int a = i < v1.length ? Integer.parseInt(v1[i]) : 0;
            int b = i < v2.length ? Integer.parseInt(v2[i]) : 0;
            if (a > b) {
                return 1;
            } else if (a < b) {
                return -1;
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        String s1 = "1.0.1";
        String s2 = "1.0";
        System.out.println(compareVersion(s1, s2));
        System.out.println(Integer.parseInt("00"));
    }
}
